//
//  textFieldViewController.m
//  UI_HLJ_Frame
//
//  Created by  毕宏伟 on 15/7/9.
//  Copyright (c) 2015年 毕宏伟. All rights reserved.
//

#import "textFieldViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#import "MytextFieldCollectionViewCell.h"
#import "HTTPTool.h"
#import "MytextModel.h"
#import "mytextcontentModel.h"
@interface textFieldViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,retain)UICollectionView *collectionView;

@property(nonatomic,retain)NSMutableArray *onePageArr;
@property(nonatomic,retain)NSMutableArray *contentArr;
@end

@implementation textFieldViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor cyanColor];
    
    [self createData];
    [self createView];
    
    
}

- (void)createData
{
    self.onePageArr =[NSMutableArray array];
    self.contentArr =[NSMutableArray array];
    NSDictionary *dic =@{@"type":@"1",@"citycode":@"0",@"searchtxt":self.nameUrl,@"pagecount":@"20",@"offset":@"0",@"sorttype":@"1"};
    [HTTPTool post:@"http://hunliji.com/p/wedding/index.php/home/APISearch" body:dic httpResult:JSON requestBodyStyle:BodyJSON success:^(id result) {
        
        NSDictionary *dic =result;
        NSArray *itemArr =dic[@"items"];
        for (NSDictionary *itemsdic in itemArr) {
            MytextModel *mytext =[[MytextModel alloc]init];
            [mytext setValuesForKeysWithDictionary:itemsdic];
            [self.onePageArr addObject:mytext];
            [mytext release];
            
            NSDictionary *contentdic =itemsdic[@"content"];
            mytextcontentModel *textcont =[[mytextcontentModel alloc]init];
            
            [textcont setValuesForKeysWithDictionary:contentdic];
            
            [self.contentArr addObject:textcont];
            [textcont release];
            
        }
        [self.collectionView reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
    
}

- (void)createView
{
    
    UICollectionViewFlowLayout *flow =[[UICollectionViewFlowLayout alloc]init];
    flow.itemSize =CGSizeMake(WIDTH, HEIGHT);
    flow.sectionInset =UIEdgeInsetsMake(0, 0, 0, 0);
    flow.minimumInteritemSpacing =0;
    flow.minimumLineSpacing =0;
    [flow setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    
    //创建collection
    self.collectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flow];
    self.collectionView.backgroundColor =[UIColor whiteColor];
    self.collectionView.delegate =self;
    self.collectionView.dataSource =self;
    [self.view addSubview:self.collectionView];
    [_collectionView release];
    
    //注册collectionView
    [self.collectionView registerClass:[MytextFieldCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MytextFieldCollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    
    
    cell.onePageArr =self.onePageArr;
    cell.contentArr =self.contentArr;
    [cell.tableView reloadData];
    
    return cell;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
